package com.xquant.common.engine.xPP.request.scene;

import java.util.ArrayList;
import java.util.List;

/**
 * @author B946
 * @date 26/09/2020 12:00
 * @description:
 */
public class SceneFactor {

    private static String OFFSET_VALUE = "0";
    private static String OFFSET_STEP = "1";

    /**
     "sceneFactor": "Price",
     "offsetType": "0",
     "offsetValues": ["-0.08", "-0.04", "0", "0.08", "0.04"],
     "steps": "5",
     "stepLength": "0.04",
     "values": ['1', '2', '3', '4']
     */

    /**
     * 情景因子："SpotPrice"，"Vol"，"Strike"，"ValueDate"，"Term"
     */
    private String sceneFactor;

    /**
     * 偏移类型
     * 0-偏移列表(offsetValues)，
     * 1-偏移阶梯(steps,stepLength)
     */
    private String offsetType;

    private List<String> offsetValues;

    private String steps;

    private String stepLength;

    private List<String> values;

    public String getSceneFactor() {
        return sceneFactor;
    }

    public void setSceneFactor(String sceneFactor) {
        this.sceneFactor = sceneFactor;
    }

    public String getOffsetType() {
        return offsetType;
    }

    public void setOffsetType(String offsetType) {
        this.offsetType = offsetType;
    }

    public List<String> getOffsetValues() {
        return offsetValues;
    }

    public void setOffsetValues(List<String> offsetValues) {
        this.offsetValues = offsetValues;
    }

    public String getSteps() {
        return steps;
    }

    public void setSteps(String steps) {
        this.steps = steps;
    }

    public String getStepLength() {
        return stepLength;
    }

    public void setStepLength(String stepLength) {
        this.stepLength = stepLength;
    }

    public List<String> getValues() {
        return values;
    }

    public void setValues(List<String> values) {
        this.values = values;
    }


    /**
     * 将情景拆分为简单情景
     *
     * @return
     */
    public List<Factor> getFactors() {
        List<Factor> factors = new ArrayList<>();
        List<String> list = null;
        String type = null;
        if (values != null && !values.isEmpty()) {
            type = Factor.VALUE_TYPE_VALUE;
            list = values;
        } else if (OFFSET_STEP.equals(offsetType)) {
            type = Factor.VALUE_TYPE_OFFSET;
            list = new ArrayList<>();
            offsetValues.add("0");
            Double length = Double.valueOf(stepLength);
            for (int i = 1; i <= Integer.valueOf(steps); i++) {
                String stepValue = String.valueOf(Double.valueOf(i + "") * length);
                offsetValues.add(stepValue);
                offsetValues.add("-" + stepValue);
            }
        } else if (OFFSET_VALUE.equals(offsetType)) {
            type = Factor.VALUE_TYPE_OFFSET;
            list = offsetValues;
        }
        for (String value : list) {
            Factor factor = new Factor();
            factor.setFactor(this.sceneFactor);
            factor.setValue(value);
            factor.setType(type);
            factors.add(factor);
        }
        return factors;
    }
}
